
<%@page import="ll.sms.web.*"%><%@ page language="java"
	import="java.util.*,ll.sms.pojo.*,org.json.simple.*"
	pageEncoding="UTF-8"%>
<%@page import="ll.sms.util.*"%>
<%@page import="ll.sms.exceptions.SmsRuntimeException"%>
<%@page import="ll.sms.interfaces.WebBusinessInterface"%>
<%
	SmsAdmin smsAdmin = (SmsAdmin) session.getAttribute("user");

	String sort = ParamUtils.getParameter(request, "sort");
	int index = ParamUtils.getIntParameter(request, "start", 0);
	int pageSize = ParamUtils.getIntParameter(request, "limit", 15);
	int currentPage = 1 + (index / pageSize);
	String dir = request.getParameter("dir");
	if (dir == null) {
		dir = "ASC";
	}

	String orderStr = null;
	if (sort != null && !sort.equals("")) {
		if(!"UOPNAME".equalsIgnoreCase(sort)){
		orderStr = " " + sort + " " + dir + " ";
		}
	}

	String condition=null;
	if (smsAdmin.getArank() == SmsConstant.ADMIN_TYPE) {
		//return;
	}else if(smsAdmin.getArank() == SmsConstant.PROXY_TYPE){
		condition = " where ucompany = '"+smsAdmin.getAid()+"' ";

	}else if(smsAdmin.getArank() == SmsConstant.OPERATOR_TYPE){
        condition = " where uids in (select ouserid from sms_operator where oadminid = '"+smsAdmin.getAid()+"') ";

	}else{

	throw new SmsRuntimeException();
	}
	int total = WebBusinessImpl.getInstance().countTable("sms_user",
			condition);
	List<SmsUser> list = WebBusinessImpl.getInstance().pageQuery(SmsUser.class, "sms_user", condition,currentPage, pageSize, orderStr);
	//system
	if("autouser".equals(ParamUtils.getParameter(request, "flag"))){
		if(list != null && list.size()!=0){
			List<SmsUser> nestList = new ArrayList<SmsUser>();
			for(SmsUser smsUser : list){
				if(SmsAppContainer.getBlackList().containsKey(smsUser.getUuname())){
					smsUser.setUavailable(-1);
				}else{
					smsUser.setUavailable(1);
				}

				nestList.add(smsUser);
			}
			list = null;
			list = nestList;
		}

	}else{
	    //将通道代码该为通道名称
	    WebBusinessInterface wb = WebBusinessImpl.getInstance();
		if(list != null && list.size()!=0){
				List<SmsUser> nestList = new ArrayList<SmsUser>();
				for(SmsUser smsUser : list){
					smsUser.setUchannel(SmsUtil.channelIdToName(smsUser.getUchannel()));
					smsUser.setUopname(wb.findOperatorNameByUserId(smsUser.getUids()));
					nestList.add(smsUser);
				}
				list = null;
				list = nestList;
			}
	}

	String s = ExtJsonBuilder.toExtJsonString(total, list);
	response.getWriter().print(s);
%>
